var status;
var text;
var itemList = new Array();
var inventoryType;
var deleteSlot;
var deleteQuantity;
var typed = 0;
var beDeletedArr = new Array();
var listq = Array(2, 5, 20);
var itemq = 0;

function start() {
    status = -1;
    action(1, 0, 0)
}

function action(a, f, h) {
    if (status == 0 && a == 0) {
        cm.dispose();
        return
    } else {
        if (a == 1) {
            status++
        } else {
            status--
        }
        if (status == 0) {
            text = "您好，在我这里可以直接分解130~150的装备，分解装备可以获得#b冬季限量币#k和#b咒语痕迹#k。\r\n\r\n";
            text += "#b#L0#了解分解说明#l\r\n";
            text += "#b#L1#我要分解装备#l\r\n";
            text += "#b#L2#一键分解130~139装备#l\r\n";
            cm.askMenu(text)
        } else {
            if (status == 1) {
                if (h == -1) {
                    h = 1
                }
                switch (h) {
                    case 0:
                        text = "#e#d分解说明#n#k：\r\n";
                        text += "130-139装备分解后可获得2个#v4310129#和2个#v4001832#\r\n";
                        text += "140-149装备分解后可获得5个#v4310129#和5个#v4001832#\r\n";
                        text += "150-159装备分解后可获得20个#v4310129#和20个#v4001832#\r\n";
                        cm.sendOk(text);
                        cm.dispose();
                        break;
                    case 1:
                        inventoryType = 1;
                        var d = cm.getInventory(inventoryType).list();
                        itemList = d.iterator();
                        text = "\t\t#e- 请选择要出售的装备 -#n\r\n\r\n#b";
                        var e = 1;
                        var c = Array();
                        while (itemList.hasNext()) {
                            var j = itemList.next();
                            if (cm.isCash(j.getItemId())) {
                                continue
                            }
                            var g = cm.getReqLevel(j.getItemId());
                            if (g < 130 || g > 150) {
                                continue
                            }
                            c[j.getPosition()] = j.getItemId()
                        }
                        for (var i in c) {
                            text += "#L" + i + "##v" + c[i] + "#";
                            if (e > 1 && e % 5 == 0) {
                                text += "\r\n"
                            }
                            e++
                        }
                        typed = 1;
                        cm.askMenu(text);
                        break;
                    case 2:
                        inventoryType = 1;
                        var d = cm.getInventory(inventoryType).list();
                        itemList = d.iterator();
                        text = "\t\t#e- 以下是准备分解的装备,请核对仔细 -#n\r\n\r\n#b";
                        var e = 1;
                        var c = Array();
                        while (itemList.hasNext()) {
                            var j = itemList.next();
                            if (cm.isCash(j.getItemId())) {
                                continue
                            }
                            var g = cm.getReqLevel(j.getItemId());
                            if (g >= 130 && g < 140) {
                                c[j.getPosition()] = j.getItemId();
                                beDeletedArr.push(j.getPosition())
                            }
                        }
                        for (var i in c) {
                            text += "#v" + c[i] + "#";
                            if (e > 1 && e % 5 == 0) {
                                text += "\r\n"
                            }
                            e++
                        }
                        text += "\r\n#r#e分解操作不可逆，请确认是否要分解以上装备？#n#k";
                        typed = 2;
                        cm.askYesNo(text);
                        break
                }
            } else {
                if (status == 2) {
                    if (typed == 1) {
                        var j = cm.getInventory(inventoryType).getItem(h);
                        if (j == null) {
                            cm.sendOk("选择的装备错误，请重新对话。");
                            cm.dispose();
                            return
                        }
                        deleteSlot = h;
                        deleteQuantity = j.getQuantity();
                        var g = cm.getReqLevel(j.getItemId());
                        itemq = getType(g);
                        if (cm.getSpace(4) < 2) {
                            cm.sendOk("其他栏格子不足，请整理后分解。");
                            cm.dispose();
                            return
                        }
                        text = "#e确定要分解#r#v" + j.getItemId() + "##z" + j.getItemId() + "# " + deleteQuantity + "个 #k吗？#k";
                        cm.sendNextPrev(text)
                    } else {
                        if (typed == 2) {
                            itemq = getType(130);
                            var b = beDeletedArr.length * itemq;
                            for (var i in beDeletedArr) {
                                cm.removeSlot(1, beDeletedArr[i], 1)
                            }
                            cm.gainItem(4310129, b);
                            cm.gainItem(4001832, b);
                            text = "分解成功，获得了#v4310129#和#v4001832#每种" + b + "个";
                            cm.sendOk(text);
                            cm.dispose()
                        }
                    }
                } else {
                    if (status == 3) {
                        if (typed == 1) {
                            cm.removeSlot(inventoryType, deleteSlot, deleteQuantity);
                            cm.gainItem(4001832, itemq);
                            cm.gainItem(4310129, itemq);
                            text = "分解成功，获得了#v4310129#和#v4001832#每种" + itemq + "个";
                            cm.sendOk(text);
                            cm.dispose()
                        }
                    }
                }
            }
        }
    }
}

function getType(a) {
    if (a >= 130 && a < 139) {
        return listq[0]
    } else {
        if (a >= 140 && a < 149) {
            return listq[1]
        } else {
            if (a >= 150 && a < 159) {
                return listq[2]
            } else {
                return 0
            }
        }
    }
}
var status = -1;